package
{
	/**
	 *
	 *@author CrazyChen 
	 *2013-4-10
	 */	
	import fl.controls.Button;
	import fl.controls.ComboBox;
	import fl.data.DataProvider;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class ToolPanel extends Sprite
	{
		
		private var combobox:ComboBox;
		
		private var openOrClose:Button;
		
		private var pageBtn:Button;
		
		private var printPlant:Button;
		
		private var showGradMap:Button;
		
		private var lineEdit:Button;
		
		private var deletePlant:Button;
		public function ToolPanel()
		{
			super();
			this.y = 480;
			initface();
		}
		
		private function initface():void
		{
			var dp:DataProvider = new DataProvider();
			dp.addItem({label:"地图"});
			dp.addItem({label:"植物"});
			combobox = new ComboBox();
			this.addChild(combobox);
			combobox.width = 60;
			combobox.dataProvider = dp;
			combobox.addEventListener(Event.CHANGE,change);
			
			openOrClose = new Button();
			this.addChild(openOrClose);
			openOrClose.width = 40;
			openOrClose.label = "关闭";
			openOrClose.x = combobox.width;
			openOrClose.addEventListener(MouseEvent.CLICK,openOrCloseHandle);
			
			pageBtn = new Button();
			this.addChild(pageBtn);
			pageBtn.x = openOrClose.x + openOrClose.width;
			pageBtn.width = 40;
			pageBtn.label = "翻页";
			pageBtn.addEventListener(MouseEvent.CLICK,TowerWarMap.instance.plant.turnPage);
			
			printPlant = new Button();
			this.addChild(printPlant);
			printPlant.x = pageBtn.x + pageBtn.width;
			printPlant.width = 100;
			printPlant.label = "输出植物数据";
			printPlant.addEventListener(MouseEvent.CLICK,TowerWarMap.instance.plantView.printPantData);
			
			showGradMap = new Button();
			this.addChild(showGradMap);
			showGradMap.x =printPlant.x  + printPlant.width;
			showGradMap.label = "格子地图显示开关";
			showGradMap.addEventListener(MouseEvent.CLICK,TowerWarMap.instance.gradMap.isShow);
			
			lineEdit = new Button();
			this.addChild(lineEdit);
			lineEdit.x = showGradMap.x + showGradMap.width;
			lineEdit.y = showGradMap.y;
			lineEdit.label = '编辑路径';
			lineEdit.addEventListener(MouseEvent.CLICK,TowerWarMap.instance.lineEdit);
			
			deletePlant = new Button();
			this.addChild(deletePlant);
			deletePlant.x = lineEdit.x + lineEdit.width;
			deletePlant.y = lineEdit.y;
			deletePlant.label= "删除植物";
			deletePlant.addEventListener(MouseEvent.CLICK,TowerWarMap.instance.plantView.deleteItem);
		}
		
		private function change(event:Event):void
		{
			
			if(combobox.selectedLabel=="地图"){
				!TowerWarMap.instance.gradMap.isCanClick ? openOrClose.label="开启" : openOrClose.label="关闭";
			}else if(combobox.selectedLabel=="植物"){
				!TowerWarMap.instance.plantView.isCanClick ? openOrClose.label="开启" : openOrClose.label="关闭";
			}
		}
		
		protected function openOrCloseHandle(event:MouseEvent):void
		{
			if(combobox.selectedLabel=="地图"){
				TowerWarMap.instance.gradMap.isCanClick = !TowerWarMap.instance.gradMap.isCanClick;
			}else if(combobox.selectedLabel=="植物"){
				TowerWarMap.instance.plantView.isCanClick = !TowerWarMap.instance.plantView.isCanClick;
			}
			if(openOrClose.label=="关闭"){
				openOrClose.label = "开启";
			}else{
				openOrClose.label = "关闭";
			}
		
		}
	}
}